package com.war.controller.system;

import com.war.pojo.system.Supplier;
import com.war.service.safeManage.UserService;
import com.war.service.system.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/supplier")
public class SupplierController {
    @Autowired(required = false)
    SupplierService supplierService;

    @RequestMapping("/selectName")
    @ResponseBody
    public List<Supplier> selectName(){
        return supplierService.selectName();
    }

    //访问warehouseManage页面
    @RequestMapping("/supplierList")
    public String list(Supplier supplier, ModelMap m){
        //查询分页数据
        HashMap<String, Object> map = supplierService.select(supplier);        //把数据传到前端
        m.put("info",map);
        //把查询条件传到前端
        m.put("CV",supplier.getConValue());
        return "basicDataManage/supplierManage/supplierManage";
    }

    //打开添加页面
    @RequestMapping("/addSupPage")
    public String addSupPage(){
        return "basicDataManage/supplierManage/addSup";
    }

    //打开修改页面
    @RequestMapping("/editSupPage")
    public String editSupPage(Supplier supplier, ModelMap m){
        Supplier s = supplierService.selectByid(supplier);
        //把数据传到前端
        m.addAttribute("supplier",s);
        return "basicDataManage/supplierManage/editSup";
    }

    //处理修改的ajax请求
    @RequestMapping("/editISup")
    @ResponseBody
    public HashMap<String,Object> editIWare(Supplier supplier){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = supplierService.editSup(supplier);
        map.put("info",info);
        return map;
    }

    //处理删除的ajax请求
    @RequestMapping("/delSup")
    @ResponseBody
    public HashMap<String,Object> delSup(Supplier supplier){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = supplierService.delSup(supplier);
        map.put("info",info);
        return map;
    }

    //处理添加用户的ajax请求
    @RequestMapping("/addSup")
    @ResponseBody
    public HashMap<String,Object> addUser(Supplier supplier){
        HashMap<String,Object> map = new HashMap<String,Object>();
        String info = supplierService.addSup(supplier);
        map.put("info",info);
        return map;
    }

}
